<template>
  <div>
    <el-button type="primary" class="add" @click="add">添加</el-button>
    <form-vue @init="getList" :info="info" ref="form" ></form-vue>
    <list-vue :arr="arr" @init="getList"  @willUpdate="willUpdate" :info="info"></list-vue>
    <el-pagination
    @current-change="changePage"
  background
  layout="prev, pager, next"
  :total="total"
  :page-size="size">
</el-pagination>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import {reqgoodslist,reqgoodscount} from '../../http/api';
import listVue from "./components/list.vue";
import formVue from './components/form.vue'
export default {
  components:{
    listVue,
    formVue
  },
  data() {
    return {
      info:{
        isshow:false,
        isAdd:false
      },
      arr:[],
      total:0,
       size: 2,//一页的条目
    page: 1,//当前页码
      
    };
  },
  computed: {
    ...mapGetters({}),
  },
  mounted() {
    this.getList()
    reqgoodscount().then(res => {
      // console.log('总数',res);
      this.total = res.data.list[0].total;
    })
  },
  methods: {
    ...mapActions({}),
    add(){
      this.info.isshow = true;
      this.info.isAdd = true;
    },
    getList(){
      reqgoodslist({size:this.size,page:this.page}).then(res => {
        this.arr = res.data.list;
      })
    },
    willUpdate(id){
        this.$refs.form.getOne(id);
    },
    changePage(e){
      this.page = e;
      this.getList()
    }
  },
};
</script>
<style scoped lang="less">
@import "../../less/index.less";
.add{
  margin: 20px;
}
</style>